const gulp = require('gulp')
const minifycss = require('gulp-minify-css')
const concat = require('gulp-concat')
const uglify = require('gulp-uglify')
const rename = require('gulp-rename')
const notify = require('gulp-notify')
const babel = require('gulp-babel')
const minifyhtml = require('gulp-minify-html')

const cssFilesPath = 'app/phoneContent/*.css'
const jsFilesPath = 'app/page-js/*.js'
const htmlFilesPath = 'app/*.html'
// gulp.task('default',function(){
//     gulp.start('minifycss')
// })

gulp.task('build',gulp.series(css,js,html,img,function(){
    console.log(`gulp build is runing`)
}))

function css(){
    return gulp.src(cssFilesPath)
    // .pipe(concat('result.css'))
    // .pipe(gulp.dest('dist/css'))
    // .pipe(rename({suffix:'.min'}))
    .pipe(minifycss())
    .pipe(gulp.dest('dist/css'))
    .pipe(notify({message:'css task is ok!'}))
}

function js(){
    return gulp.src(jsFilesPath)
    // .pipe(concat('result.js'))
    // .pipe(gulp.dest('dist/js'))
    .pipe(babel({presets: ['@babel/preset-env']}))
    // .pipe(rename({suffix:'.min'}))
    .pipe(uglify())
    .pipe(gulp.dest('dist/page-js'))
    .pipe(notify({message:'js task is ok!'}))
}

function html(){
    // return gulp.src(['src/*.html','src/threeStar/*.html'])
    return gulp.src(htmlFilesPath)
    .pipe(minifyhtml())
    .pipe(gulp.dest('dist'))
    .pipe(notify({message:'html task is ok!'}))
}

function img(){
    return gulp.src('src/public/*.ico')
    .pipe(gulp.dest('dist/public'))
}